Inserts a Javascript into the Head of the document.
#include <IE.au3>
_IEHeadInsertEventScript ( ByRef $o_object, $s_htmlFor, $s_event, $s_script )
Parameters
$o_object | Object variable of an InternetExplorer.Application, Window or Frame object |
$s_htmlFor | The HTML element for event monitoring (e.g. "document" or an element ID) |
$s_event | The event to monitor (e.g. "onclick" or "oncontextmenu") |
$s_script | Javascript string to be executed |
Return Value
Success: | Returns 1 |
Failure: | Returns 0 and sets @ERROR |
@Error: | 0 ($_IEStatus_Success) = No Error |
3 ($_IEStatus_InvalidDataType) = Invalid Data Type | |
@Extended: | Contains invalid parameter number |
Remarks
Using ObjEvent, AutoIt is able to be notified of events via COM, but it manages them asynchronously rather than synchronously as they are handled in the browser context. This routine allows you to inject code that is managed inside the browser context.
Related
None.
Example
; *******************************************************
; Example 1 - Open a browser with the basic example page, insert an
; event script into the head of the document that creates
; a JavaScript alert when someone clicks on the document
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
_IEHeadInsertEventScript ($oIE, "document", "onclick", "alert('Someone clicked the document!');")
; *******************************************************
; Example 2 - Open a browser with the basic example page, insert an
; event script into the head of the document that creates
; a JavaScript alert when someone tries to right-click on the
; document and then the event script returns "false" to prevent
; the right-click context menu from appearing
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('No Context Menu');return false")